package com.bachongLightNovel.message.controller;

import com.bachongLightNovel.message.service.MessageService;
import com.bachongLightNovel.model.pojo.message.Message;
import com.bachongLightNovel.model.vo.message.MessageVo;
import com.bachongLightNovel.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @author vermouth
 */

@RestController
@RequestMapping("/api/message")
@Slf4j
public class MessageController {

    @Autowired
    private MessageService messageService;

    /**
     * 获取当前登录用户的消息列表
     * @param :
     * @return Result
     * @author vermouth
     */
    @GetMapping("get-messages")
    public Result getCurrentMessages(){
        log.info("获取当前登录用户的消息列表");
        List<MessageVo> voList= messageService.getCurrentMessages();
        return Result.success(voList);
    }

    /**
     * 根据id删除此条消息
     * @param id:
     * @return Result
     * @author vermouth
     */
    @DeleteMapping("remove-message/{id}")
    public Result removeMessageById(@PathVariable Long id){
        log.info("根据id删除此条消息:{}",id);
        messageService.removeMessageById(id);
        return Result.success();
    }

    /**
     * 向用户发送消息
     * @param message:
     * @return Result
     * @author vermouth
     */
    @PostMapping("send")
    public Result sendMessage(@RequestBody Message message){
        log.info("向用户发送消息：{}",message);
        messageService.sendMessage(message);
        return Result.success();
    }
}
